﻿using Alos.Entity;
using Alos.IRepository;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alos.Repository
{
    public class ReLessionRepository : BaseRepository<ReLession>, IReLessionRepository
    {
        /// <summary>
        /// 根据用户编号获取教材
        /// </summary>
        /// <param name="id"></param>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public IEnumerable<dynamic> GetStepByLessionID(int id)
        {
            var sql = Sql.Builder.Append(@"select F.[Version],F.[SubVersion],CASE UpOrDown WHEN 1 THEN '上册' WHEN 2 THEN '下册' END AS UpOrDown,W.SubjectName,A.LessonID, B.StepName,B.StepID, (SELECT D.PointName FROM [dbo].[Chapter] D WHERE D.ID=C.ChapterID) PointName,C.LessonTitle,C.ClassPeriod,C.PPTResourceID   from  ReLessonResourceIndex A
                              left join ReCourseProcessStep B on A.StepID=B.StepID 
                              left join ReLession c on c.ID =A.LessonID
                              LEFT JOIN [dbo].[Chapter] Z ON C.ChapterID=Z.ID
                              LEFT JOIN TeachingMaterial F ON Z.TeachingMaterialID=F.ID
                              LEFT JOIN DicSubject W ON W.SubjectCode=F.SubjectCode
                              where A.LessonID =@0 order by A.StepNo ", id);
            return DBContext.Query<dynamic>(sql);

        }

        public IEnumerable<dynamic> GetReLessionClassPeriodByChapterID(int cid, int uid)
        {
            var sql = Sql.Builder.Append(@"SELECT A.ClassPeriod,A.ID,A.LessonMode,ISNULL(B.[Status],4) AS Status,ISNULL(B.ClassID,0)AS ClassID FROM [dbo].[ReLession] A LEFT JOIN ReArrangeRecord B ON B.LessonID=A.ID
                                 WHERE A.ChapterID=@0 AND A.LessonTeacher=@1 AND A.LessonTitle IS NOT NULL ", cid, uid);
            return DBContext.Query<dynamic>(sql);
        }
    }
}
